<template>
	<view class="container">
		<!-- 用户信息区域 -->
		<view class="user-profile">
			<image class="avatar" :src="userInfo.avatar_url || '/static/logo.png'" mode="aspectFill"></image>
			<view class="user-info">
				<text class="username">{{ userInfo.nickname || '用户昵称' }}</text>
				<!-- <text class="user-id">ID: {{ userInfo.openid || '123456789' }}</text> -->
			</view>
			<view class="edit-profile" @click="goToUserProfile">
				<text class="edit-text">编辑资料</text>
			</view>
		</view>
		
		<!-- 功能菜单列表 -->
		<view class="menu-list">
			<view class="menu-item" @click="goToPage('orders')">
				<view class="menu-content">
					<text class="menu-title">我的订单</text>
				</view>
				<view class="menu-arrow">
					<text class="arrow">›</text>
				</view>
			</view>
			
			<view class="menu-item" @click="goToPage('favorites')">
				<view class="menu-content">
					<text class="menu-title">我的收藏</text>
				</view>
				<view class="menu-arrow">
					<text class="arrow">›</text>
				</view>
			</view>
			
			<view class="menu-item" @click="goToPage('addresses')">
				<view class="menu-content">
					<text class="menu-title">收货地址</text>
				</view>
				<view class="menu-arrow">
					<text class="arrow">›</text>
				</view>
			</view>
			
			<!-- 导入菜单功能 -->
			<view class="menu-item import-menu-item" @click="goToImportMenu">
				<view class="menu-content">
					<text class="menu-title">导入菜单</text>
				</view>
				<view class="menu-arrow">
					<text class="arrow">›</text>
				</view>
			</view>
		</view>
		
		<!-- 设置选项 -->
		<view class="settings-list">
			<view class="settings-title">
				<text>设置</text>
			</view>
			
			<view class="setting-item">
				<view class="setting-content">
					<text class="setting-title">消息通知</text>
				</view>
				<switch class="setting-switch" checked />
			</view>
			
			<view class="setting-item" @click="goToPage('privacy')">
				<view class="setting-content">
					<text class="setting-title">隐私设置</text>
				</view>
				<view class="setting-arrow">
					<text class="arrow">›</text>
				</view>
			</view>
			
			<view class="setting-item" @click="goToPage('about')">
				<view class="setting-content">
					<text class="setting-title">关于我们</text>
				</view>
				<view class="setting-arrow">
					<text class="arrow">›</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '@/config/api.js'
	export default {
		data() {
			return {
				userInfo: {
					openid: '',
					nickname: '',
					avatar: '',
					signature: ''
				}
			}
		},
		onLoad() {
			// 页面加载时获取用户信息
			this.loadUserInfo();
		},
		onShow() {
			// 页面显示时重新加载用户信息（从用户信息页面返回时）
			this.loadUserInfo();
		},
		methods: {
			// 加载用户信息
			loadUserInfo() {
				try {
					const userInfo = uni.getStorageSync('userInfo');
					const openid = uni.getStorageSync('openid');
					
					if (userInfo) {
						this.userInfo = { ...userInfo };
					} else if (openid) {
						// 如果没有完整的用户信息，至少显示 openid
						this.userInfo.openid = openid;
					}
				} catch (e) {
					console.error('获取用户信息失败', e);
				}
			},
			
			// 跳转到用户信息页面
			goToUserProfile() {
				uni.navigateTo({
					url: '/pages/user/user'
				});
			},
			
			// 跳转到其他页面
			goToPage(page) {
				uni.showToast({
					title: `跳转到${page}页面`,
					icon: 'none'
				});
				// 这里可以实现页面跳转逻辑
			},
			
			// 跳转到导入菜单页面
			goToImportMenu() {
				uni.navigateTo({
					url: '/pages/importmenu/importmenu'
				});
			}
		}
	}
</script>

<style scoped>
	.container {
		background-color: #f8f8f8;
		min-height: 100vh;
		padding-bottom: 20rpx;
	}
	
	.user-profile {
		background-color: white;
		padding: 40rpx 30rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
	}
	
	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		margin-right: 30rpx;
	}
	
	.user-info {
		flex: 1;
	}
	
	.username {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10rpx;
	}
	
	.user-id {
		font-size: 26rpx;
		color: #999;
	}
	
	.edit-profile {
		padding: 10rpx 20rpx;
		border: 1rpx solid #f0ad4e;
		border-radius: 30rpx;
	}
	
	.edit-text {
		font-size: 26rpx;
		color: #f0ad4e;
	}
	
	.menu-list {
		background-color: white;
		margin-bottom: 20rpx;
		box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
	}
	
	.menu-item {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #eee;
	}
	
	.menu-item:last-child {
		border-bottom: none;
	}
	
	.import-menu-item {
		background-color: #fff9f0;
	}
	
	.menu-icon {
		margin-right: 20rpx;
	}
	
	.iconfont {
		font-size: 40rpx;
	}
	
	.menu-content {
		flex: 1;
	}
	
	.menu-title {
		font-size: 32rpx;
		color: #333;
		margin-bottom: 5rpx;
	}
	
	.menu-desc {
		font-size: 24rpx;
		color: #999;
	}
	
	.menu-arrow {
		margin-left: 20rpx;
	}
	
	.arrow {
		color: #ccc;
		font-size: 36rpx;
	}
	
	/* 使用 CSS 伪元素创建箭头符号 */
	.arrow::after {
		content: "›";
	}
	
	.settings-list {
		background-color: white;
		box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
	}
	
	.settings-title {
		padding: 20rpx 30rpx;
		font-size: 30rpx;
		color: #666;
		border-bottom: 1rpx solid #eee;
	}
	
	.setting-item {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #eee;
	}
	
	.setting-item:last-child {
		border-bottom: none;
	}
	
	.setting-content {
		flex: 1;
	}
	
	.setting-title {
		font-size: 32rpx;
		color: #333;
	}
	
	.setting-switch {
		transform: scale(0.8);
	}
	
	.setting-arrow {
		margin-left: 20rpx;
	}
</style>